package com.nft.service.school.controller;

import com.nft.constant.response.ResponseConstants;
import com.nft.paging.Paginator;
import com.nft.po.NftResponse;
import com.nft.service.school.req.*;
import com.nft.service.school.resp.*;
import com.nft.service.school.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/userApp")
@Api(tags = "用户手机端模块")
public class UserAppController {

    @Autowired
    private SysDeptService sysDeptService;
    @Autowired
    private SysUserService userAppService;
    @Autowired
    private SchoolClassesService schoolClassesService;
    @Autowired
    private SchoolActivityService schoolActivityService;
    @Autowired
    private SchoolPayrecordService schoolPayrecordService;
    @Autowired
    private SchoolConsumeService schoolConsumeService;
    @Autowired
    private SchoolStudentService schoolStudentService;

    @ApiOperation(value="学校分页信息")
    @RequestMapping(value = "/getSchoolList", method = RequestMethod.POST)
    public NftResponse<Paginator<SysDeptResp>> getSchoolList(@RequestBody SysDeptReq query) {
        return sysDeptService.getSchoolList(query);
    }

    @RequestMapping(value = "/getSchoolAllList", method = RequestMethod.POST)
    public NftResponse<List<SysDeptResp>> getSchoolAllList(@RequestBody SysDeptReq query) {
        return sysDeptService.getSchoolAllList(query);
    }

    @ApiOperation(value="学校详细信息")
    @RequestMapping(value = "/getSchoolInfo", method = RequestMethod.GET)
    public NftResponse<SysDeptResp> getSchoolInfo(@RequestParam("deptId") Long deptId) {
        return sysDeptService.getSchoolInfoById(deptId);
    }

    @ApiOperation(value="活动公告分页信息")
    @RequestMapping(value = "/getNoticeList", method = RequestMethod.POST)
    public NftResponse<Paginator<SchoolActivityResp>> getNoticeList(@RequestBody SchoolActivityReq query) {
        return schoolActivityService.getActivityList(query);
    }

    @ApiOperation(value="活动公告详细信息")
    @RequestMapping(value = "/getNoticeInfo", method = RequestMethod.GET)
    public NftResponse<SchoolActivityResp> getNoticeInfo(@RequestParam("id") Long id) {
        return schoolActivityService.getActivityInfoById(id);
    }

    @ApiOperation(value="根据手机号获取用户信息")
    @RequestMapping(value = "/getUserAppInfoByPhone", method = RequestMethod.GET)
    public NftResponse<SysUserResp> getUserAppInfoByPhone(@RequestParam("phone") String phone) {
        return userAppService.getUserAppInfoByPhone(phone);
    }

    @ApiOperation(value="根据用户id获取用户信息")
    @RequestMapping(value = "/getUserAppInfoByUserId", method = RequestMethod.POST)
    public NftResponse<SysUserResp> getUserAppInfoByUserId(@RequestBody SysUserReq query) {
        return userAppService.getUserAppInfoById(query.getUserId());
    }

    @ApiOperation(value="用户信息修改")
    @RequestMapping(value = "/updateUserAppInfo", method = RequestMethod.POST)
    public NftResponse<Boolean> updateUserAppInfo(@RequestBody SysUserReq query) {
        return userAppService.updateUserAppInfo(query);
    }

    @ApiOperation(value="用户实名认证")
    @RequestMapping(value = "/realNameUser", method = RequestMethod.POST)
    public NftResponse<Boolean> realNameUser(@RequestBody SysUserReq query) {
        return userAppService.updateUserAppInfo(query);
    }

    @ApiOperation(value="修改手机号")
    @RequestMapping(value = "/updateUserAppPhone", method = RequestMethod.POST)
    public NftResponse<Boolean> updateUserAppPhone(@RequestHeader("userId") String userId, @RequestBody SysUserReq query) {
        if(userId == null || userId == ""){
            return new NftResponse<>(ResponseConstants.TOKEN_CODE,"鉴权失败",null);
        }
        query.setId(Long.valueOf(userId));
        return userAppService.updateUserAppInfo(query);
    }

    @ApiOperation(value="获取用户所属学校信息")
    @RequestMapping(value = "/getUserSchoolListByPhone", method = RequestMethod.POST)
    public NftResponse<List<SysDeptResp>> getUserSchoolListByPhone(@RequestBody SysUserReq query) {
        return sysDeptService.getSchoolListByPhone(query);
    }

    @ApiOperation(value="获取用户所属班级信息")
    @RequestMapping(value = "/getUserClassesListByUserId", method = RequestMethod.POST)
    public NftResponse<List<SchoolClassesResp>> getUserClassesListByUserId(@RequestBody SysUserReq query) {
        return schoolClassesService.getClassesListByUserId(query);
    }

    @ApiOperation(value="获取缴费信息")
    @RequestMapping(value = "/getPayRecords", method = RequestMethod.POST)
    public NftResponse<Paginator<SchoolPayrecorddResp>> getPayRecords(@RequestBody SchoolPayrecordReq query) {
        return schoolPayrecordService.getPayrecordList(query);
    }

    @ApiOperation(value="获取总余额信息")
    @RequestMapping(value = "/getPayRemainder", method = RequestMethod.GET)
    public NftResponse<SchoolPayrecordResp> getPayRemainder(@RequestParam("phone") String phone) {
        return schoolPayrecordService.getPayRemainder(phone);
    }

    @ApiOperation(value="获取耗课信息")
    @RequestMapping(value = "/getConsume", method = RequestMethod.POST)
    public NftResponse<Paginator<SchoolConsumeResp>> getConsume(@RequestBody SchoolConsumeReq query) {
        return schoolConsumeService.getConsumeList(query);
    }

    @ApiOperation(value="获取学生耗课信息")
    @RequestMapping(value = "/getXsConsume", method = RequestMethod.POST)
    public NftResponse<Paginator<SchoolStudentResp>> getXsConsume(@RequestBody SchoolStudentReq query) {
        return schoolStudentService.getStudentConsumeList(query);
    }

    @ApiOperation(value="耗课信息")
    @RequestMapping(value = "/realConsume", method = RequestMethod.POST)
    public NftResponse<Boolean> realConsume(@RequestBody SchoolConsumeReq query) {
        return schoolConsumeService.insertConsumeInfos(query);
    }

    @ApiOperation(value="获取学生列表信息")
    @RequestMapping(value = "/getXsList", method = RequestMethod.POST)
    public NftResponse<List<SchoolStudentResp>> getXsList(@RequestBody SchoolStudentReq query) {
        return schoolStudentService.getStudentList(query);
    }
}
